package com.hermes.biz.dao.item.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.hermes.biz.common.model.item.ItemUserRelationDO;
import com.hermes.biz.dao.item.UserInterestedItemDAO;

public class UserInterestedItemDAOImpl extends SqlMapClientDaoSupport implements UserInterestedItemDAO {

	private Logger log = Logger.getLogger(UserInterestedItemDAOImpl.class);

	
	public List<ItemUserRelationDO> getUserInterestedItems(long userId) {
		 try {
		 	
			 @SuppressWarnings("unchecked")
			List<ItemUserRelationDO>  resultList = this.getSqlMapClientTemplate().getSqlMapClient().queryForList("UserInterestedItemDAO.getUserInterestedItems",userId);
			 return resultList;
		 } catch (SQLException e) {
		
		 		log.error(e);
		 }		
		 return null;
	}

	public boolean insertUserInterestedItem(ItemUserRelationDO itemUserRelationDO) {
		try {
			
	 		this.getSqlMapClientTemplate().getSqlMapClient().insert("UserInterestedItemDAO.insertUserInterestedItem",itemUserRelationDO);
		
		} catch (SQLException e) {
			
	 		log.error(e);
	 		return false;
		}
		return true;
	}

	public boolean deleteUserInterestedItem(long userId, long itemId) {

		try {
			HashMap<String,Long> param = new HashMap<String,Long>();
			param.put("userId", userId);
			param.put("itemId", itemId);
			this.getSqlMapClientTemplate().getSqlMapClient().delete("UserInterestedItemDAO.deleteUserInterestedItem", param);
		
		} catch (SQLException e) {
			
			log.error(e);
			return false;
		}
		return true;
	}
	
	public ItemUserRelationDO  getUserInterestedItem(long userId,long itemId) {
		 try {
		 	
			HashMap<String,Long> param = new HashMap<String,Long>();
			param.put("userId", userId);
			param.put("itemId", itemId);
			ItemUserRelationDO  result = (ItemUserRelationDO) this.getSqlMapClientTemplate().getSqlMapClient().queryForObject("UserInterestedItemDAO.getUserInterestedItem",param);
			return result;
		 } catch (SQLException e) {
		
		 		log.error(e);
		 }		
		 return null;
	}
}
